<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改产品规格')" />
    <th:block th:include="include :: ztree-css" />
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-specification-edit" th:object="${specification}">
        <input id="speId" name="speId" type="hidden" th:field="*{speId}"/>
        <div class="form-group">
            <label class="col-sm-3 control-label ">系列名称：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="speName" id="speName" th:field="*{speName}" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">系列备注：</label>
            <div class="col-sm-8">
                <textarea id="speDesc" name="speDesc" class="form-control" th:field="*{speDesc}">[[*{speDesc}]]</textarea>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: ztree-js" />
<script type="text/javascript">

    $("#form-specification-edit").validate({
        onkeyup: false,
        rules:{
            speName:{
                remote: {
                    url: ctx + "datum/specification/checkSpeNameUnique",
                    type: "post",
                    dataType: "json",
                    data: {
                        "speId": function() {
                            return $("#speId").val();
                        },
                        "speName": function() {
                            return $.common.trim($("#speName").val());
                        }
                    },
                    dataFilter: function(data, type) {
                        return $.validate.unique(data);
                    }
                }
            },
            roleSort:{
                digits:true
            },
        },
        messages: {
            "speName": {
                remote: "产品规格名称已经存在"
            },
        },
        focusCleanup: true
    });

    function edit() {
        var speId = $("input[name='speId']").val();
        var speName = $("input[name='speName']").val();
        var speDesc = $("textarea[name='speDesc']").val();
        $.ajax({
            cache : true,
            type : "POST",
            url : ctx + "datum/specification/edit",
            data : {
                "speId": speId,
                "speName": speName,
                "speDesc": speDesc,
            },
            async : false,
            error : function(request) {
                $.modal.alertError("系统错误");
            },
            success : function(data) {
                $.operate.successCallback(data);
            }
        });
    }

    function submitHandler() {
        if ($.validate.form()) {
            edit();
        }
    }
</script>
</body>
</html>
